import {ActivatedRouteSnapshot, CanActivate, Route, Router, RouterStateSnapshot, UrlTree} from "@angular/router";
import {Observable} from "rxjs";
import {Injectable} from "@angular/core";
import {AuthService} from "./auth.service";
@Injectable({
  providedIn: "root"
})
export class AuthGuard implements CanActivate{
  constructor(private router: Router,private authService: AuthService) {
  }
  canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
    if(this.authService.getIsLoggedIn()){
      return true;
    }else{
      this.router.navigate(["/lostorfinds/account"]);
      return false;
    }
  }

}
